package com.bianmaba.wdc.controller;

import com.bianmaba.spring.supports.data.beans.basc.Result;
import com.bianmaba.wdc.service.WeekdayCalculationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RequestMapping(value = "/api/wdc")
@RestController
public class WeekdayCalculationController {
    @Autowired
    private WeekdayCalculationService weekdayCalculationService;

    @RequestMapping(value = "calculate")
    public Result calculate(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
        if (start == null || end == null) {
            return new Result(false, "计算错误，输入参数“start”、“end”不能为空！");
        }
        if (start.getTime() >= end.getTime()) {
            return new Result(false, "计算错误，输入参数“start”必须大于“end”！");
        }
        int weekday = weekdayCalculationService.calculate(start, end);
        return new Result(true, null, weekday);
    }
}
